package com.medicine.hbp.adapter;

import org.kymjs.kjframe.KJBitmap;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.medicine.hbp.R;
import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.laberInfoVo;
import com.medicine.hbp.ui.ClassificationDetailActivity;
import com.medicine.hbp.uitl.CommUtil;
import com.umeng.socialize.utils.Log;

public class HomeAdapter extends MyBaseAdapter {
	private LayoutInflater inflater;
	KJBitmap bitmap = new KJBitmap();

	public HomeAdapter(Activity activity) {
		this.activity = activity;
		inflater = LayoutInflater.from(activity);
	}

	// String Jqrd;
	// public void setJqrd(String Jqrd){
	// this.Jqrd=Jqrd;
	// notifyDataSetChanged();
	//
	// }
	int i = 0;
	public void setI(int i) {
		this.i = i;
	}
	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.item_home, null);
			holder.img_tu = (ImageView) view.findViewById(R.id.img_tu);
			holder.txt_title = (TextView) view.findViewById(R.id.txt_title);
			holder.txt_paiming = (TextView) view.findViewById(R.id.txt_paiming);
			holder.txt_paiming_num = (TextView) view
					.findViewById(R.id.txt_paiming_num);
			holder.txt_paiming_tj = (TextView) view
					.findViewById(R.id.txt_paiming_tj);
			holder.txt_jknum = (TextView) view.findViewById(R.id.txt_jknum);
			holder.txt_wznum = (TextView) view.findViewById(R.id.txt_wznum);
			holder.txt_llnum = (TextView) view.findViewById(R.id.txt_llnum);
			holder.txt_jknumleft = (TextView) view
					.findViewById(R.id.txt_jknumleft);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final laberInfoVo vo = (laberInfoVo) getItem(position);
		if (vo != null) {
			if (vo.laberIndex==0) {
				holder.txt_paiming_num.setVisibility(View.GONE);
				holder.txt_paiming.setVisibility(View.GONE);
				holder.txt_paiming_tj.setVisibility(View.VISIBLE);
			}else{
				if (vo.laberIndex == 1) {
					holder.txt_paiming_num.setVisibility(View.GONE);
					holder.txt_paiming.setVisibility(View.VISIBLE);
					holder.txt_paiming_tj.setVisibility(View.GONE);
					holder.txt_paiming.setText("排名第一");
				} else if (vo.laberIndex == 2) {
					holder.txt_paiming_num.setVisibility(View.GONE);
					holder.txt_paiming.setVisibility(View.VISIBLE);
					holder.txt_paiming_tj.setVisibility(View.GONE);
					holder.txt_paiming.setText("排名第二");
				} else if (vo.laberIndex == 3) {
					holder.txt_paiming_num.setVisibility(View.GONE);
					holder.txt_paiming.setVisibility(View.VISIBLE);
					holder.txt_paiming_tj.setVisibility(View.GONE);
					holder.txt_paiming.setText("排名第三");
				} else {
					holder.txt_paiming_num.setVisibility(View.VISIBLE);
					holder.txt_paiming.setVisibility(View.GONE);
					holder.txt_paiming_tj.setVisibility(View.GONE);
					holder.txt_paiming_num.setText(vo.laberIndex + "");
				}
			}

			if (position > 80 || vo.laberHealthNumber < 1) {
				holder.txt_jknum.setVisibility(View.GONE);
				holder.txt_jknumleft.setVisibility(View.GONE);
			} else {
				holder.txt_jknum.setVisibility(View.VISIBLE);
				holder.txt_jknumleft.setVisibility(View.VISIBLE);
			}
			holder.txt_title.setText(vo.laberName);
			holder.txt_jknum.setText(String.valueOf(vo.laberHealthNumber));
			holder.txt_wznum.setText(String.valueOf(vo.laberArtNumber));
			holder.txt_llnum.setText(String.valueOf(vo.laberViewNumber));
			if (TextUtils.isEmpty(vo.laberImg)) {
				holder.img_tu.setImageResource(R.mipmap.imgceshi2);
			} else {
				bitmap.display(holder.img_tu, vo.laberImg);
			}
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					Intent intent = new Intent(activity,
							ClassificationDetailActivity.class);
					intent.putExtra("name", vo.laberName);
					intent.putExtra("id", String.valueOf(vo.laberId));
					intent.putExtra("numone", String.valueOf(vo.laberArtNumber));
					intent.putExtra("numtwo",String.valueOf(vo.laberViewNumber));
					intent.putExtra("Status", vo.laberTitleStatus);
					intent.putExtra("Url", vo.laberTitleUrl);
					activity.startActivity(intent);
				}
			});
		}
		return view;
	}

	class ViewHolder {
		TextView txt_jknumleft;
		TextView txt_title;
		TextView txt_paiming;
		TextView txt_jknum;
		TextView txt_wznum;
		TextView txt_llnum;
		TextView txt_paiming_num;
		TextView txt_paiming_tj;
		ImageView img_tu;
	}
}
